package com.huluobo.a2109kotlinshopping.home

import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2109kotlinshopping.R
import com.huluobo.a2109kotlinshopping.databinding.ItemNavBinding

/**
 *  Created by LC on 2024/1/13.
 *  万能适配器的DataBinding写法
 *  需要创建对应的ViewHolder来获取DataBinding中的布局,用于传递Bean类对象
 */
class HomeNavAdapter(list: MutableList<NavBean>) :
    BaseQuickAdapter<NavBean, HomeNavAdapter.NavViewHolder>(R.layout.item_nav, list) {
    class NavViewHolder(var binding: ItemNavBinding) : BaseViewHolder(binding.root)

    override fun convert(helper: NavViewHolder, item: NavBean) {
        helper.binding.navBean = item
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NavViewHolder {
        val dataBinding = ItemNavBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return NavViewHolder(dataBinding)
    }
}